package org.chengn.level_middle.context162;

/**
 * @Title: Context162
 * @Author ChengN
 * @Package org.chengn.level_middle.context162
 * @Date 2023/12/18 1:14
 * @description: 寻找峰值
 */
public class Context162 {
    public int findPeakElement(int[] nums) {
        int l = 0, r = nums.length - 1;
        while (l < r) {
            int mid = (l + r) >> 1;
            if ((mid < 1 || nums[mid] > nums[mid - 1]) && (mid > nums.length - 2 || nums[mid] > nums[mid + 1])) {
                return mid;
            } else if (nums[mid] > nums[mid + 1] && nums[mid] < nums[mid - 1]) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }
        return l;
    }
}
